package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.SysAcceptancecontract;
import com.ruoyi.system.service.ISysAcceptancecontractService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAcceptancegoods;
import com.ruoyi.system.service.ISysAcceptancegoodsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供货验收货物Controller
 * 
 * @author ruoyi
 * @date 2020-12-13
 */
@Controller
@RequestMapping("/system/acceptancegoods")
public class SysAcceptancegoodsController extends BaseController
{
    private String prefix = "system/acceptancegoods";

    @Autowired
    private ISysAcceptancegoodsService sysAcceptancegoodsService;
    @Autowired
    private ISysAcceptancecontractService sysAcceptancecontractService;

    @RequiresPermissions("system:acceptancegoods:view")
    @GetMapping()
    public String acceptancegoods()
    {
        return prefix + "/acceptancegoods";
    }

    /**
     * 查询供货验收货物列表
     */
    @RequiresPermissions("system:acceptancegoods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysAcceptancegoods sysAcceptancegoods)
    {
        startPage();
        List<SysAcceptancegoods> list = sysAcceptancegoodsService.selectSysAcceptancegoodsList(sysAcceptancegoods);
        return getDataTable(list);
    }

    /**
     * 导出供货验收货物列表
     */
    @RequiresPermissions("system:acceptancegoods:export")
    @Log(title = "供货验收货物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysAcceptancegoods sysAcceptancegoods)
    {
        List<SysAcceptancegoods> list = sysAcceptancegoodsService.selectSysAcceptancegoodsList(sysAcceptancegoods);
        ExcelUtil<SysAcceptancegoods> util = new ExcelUtil<SysAcceptancegoods>(SysAcceptancegoods.class);
        return util.exportExcel(list, "acceptancegoods");
    }

    /**
     * 新增供货验收货物
     */
    @GetMapping("/add/{acceptanceContractId}")
    public String add(@PathVariable("acceptanceContractId") Long acceptanceContractId, ModelMap mmap)
    {
        SysAcceptancecontract sysAcceptancecontract = sysAcceptancecontractService.selectSysAcceptancecontractById(acceptanceContractId);
        mmap.put("shenbaoId",sysAcceptancecontract.getAcceptanceContractId());
        mmap.put("shenbao",sysAcceptancecontract.getUnitNumber());
        return prefix + "/add";
    }

    /**
     * 新增保存供货验收货物
     */
    @RequiresPermissions("system:acceptancegoods:add")
    @Log(title = "供货验收货物", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysAcceptancegoods sysAcceptancegoods)
    {

        return toAjax(sysAcceptancegoodsService.insertSysAcceptancegoods(sysAcceptancegoods));
    }

    /**
     * 修改供货验收货物
     */
    @GetMapping("/edit/{acceptanceGoodsId}")
    public String edit(@PathVariable("acceptanceGoodsId") Long acceptanceGoodsId, ModelMap mmap)
    {
        SysAcceptancegoods sysAcceptancegoods = sysAcceptancegoodsService.selectSysAcceptancegoodsById(acceptanceGoodsId);
        mmap.put("sysAcceptancegoods", sysAcceptancegoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存供货验收货物
     */
    @RequiresPermissions("system:acceptancegoods:edit")
    @Log(title = "供货验收货物", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysAcceptancegoods sysAcceptancegoods)
    {
        return toAjax(sysAcceptancegoodsService.updateSysAcceptancegoods(sysAcceptancegoods));
    }

    /**
     * 删除供货验收货物
     */
    @RequiresPermissions("system:acceptancegoods:remove")
    @Log(title = "供货验收货物", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysAcceptancegoodsService.deleteSysAcceptancegoodsByIds(ids));
    }
}
